import pymysql
class mysql:
    def __init__(self,host,port,database,root,password,charset):
        self.host=host
        self.port=port
        self.database=database
        self.root= root
        self.password= password
        self.charset=charset

    def add_person(self,sql,data=None):
        db = pymysql.connect(host=self.host, port=self.port, database=self.database, user=self.root,password= self.password,charset=self.charset)
        try:
            with db.cursor() as cursor:
                num=cursor.execute(sql,data)
                db.commit()
                print(num)
        except Exception as e:
            print("操作异常",e)
        finally:
            db.close()
def add_person():
    con=mysql('localhost',3306,'pytest','root','123456','utf8')
    for i in range(0,10):
        name=input("请输入姓名：")
        age=int(input("请输入年龄"))
        sex=input("请输入性别：")
        high=float(input("请输入身高(如1.72):"))
        data=(name,age,sex,high)
        sql=f"insert into person values {data}"
        con.add_person(sql)
